//用户反馈

const dealRequestSuccess=(res,successTitle,successComplete,falseTitle,falseComplete)=>{
  wx.hideLoading()
  if(ifRequestSuccess(res)){
    showSuccess(successTitle,successComplete)
  }else{
    showISee(falseTitle,res.data.message,falseComplete)
  }
}

const ifRequestSuccess=(successRes)=>{
  return !(typeof(successRes.data.success)==='boolean'&&successRes.data.success===false)
}

/**
 * @param {Sring} title 
 * @param {Number} timeout 
 * @param {Function} complete 
 */
const showLoading=(timeout=2000)=>{
  wx.showLoading({
    title: '加载中',
    mask:true,
  })
}

const showISee=(title,message,complete)=>{
  wx.showModal({
    title: title,
    content: message,
    showCancel: false,
    confirmText: "我知道了",
    complete: (res) => {
      complete&&(complete)
    }
  })
}
const showSuccess=(title,complete)=>{
  wx.showToast({
    title: title,
    icon: 'success',
    complete: (res) => {
      complete&&(complete)
      // wx.navigateBack(2)
    }
  })
}
export {
  showLoading,
  showISee,
  showSuccess,
  ifRequestSuccess,
  dealRequestSuccess
}